import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-06-25
 * Time: 22:14
 */
//https://leetcode.cn/problems/evaluate-reverse-polish-notation/
    //给你一个字符串数组 tokens ，表示一个根据 逆波兰表示法 表示的算术表达式。
public class Test {
    public static int evalRPN(String[] arr) {
        Stack<String> p=new Stack();
        for(int i=0;i<arr.length;i++){
            if(arr[i].equals("+")||arr[i].equals("-")||arr[i].equals("*")||arr[i].equals("/")){
                int n1=Integer.parseInt(p.pop());
                int n2=Integer.parseInt(p.pop());
                switch(arr[i]){
                    case "+":p.push(String.valueOf(n2+n1));break;
                    case "-":p.push(String.valueOf(n2-n1));break;
                    case "*":p.push(String.valueOf(n2*n1));break;
                    case "/":p.push(String.valueOf(n2/n1));break;
                }
            }
            else{
                p.push(arr[i]);
            }
        }
        return Integer.parseInt(p.peek());
    }
    public static void main(String[] args) {
        String[] arr={"10","6","9","3","+","-11","*","/","*","17","+","5","+"};
        System.out.println(evalRPN(arr));
    }
}
